﻿#region Using

using System;
using System.Xml.Serialization;

using Common.Base;
using Common.Enums;

using GameCommon.Manager;

using Menu.Components;

using Microsoft.Xna.Framework.Graphics;

using Texture = Menu.Components.Texture;

#endregion

namespace Menu.XmlEntities
{
    [Serializable]
    public class XmlTexture : XmlBaseEntity
    {
        [XmlAttribute("X")]
        public int X { get; set; }

        [XmlAttribute("Y")]
        public int Y { get; set; }

        [XmlAttribute("Width")]
        public int Width { get; set; }

        [XmlAttribute("Height")]
        public int Height { get; set; }

        [XmlAttribute("VerticalAlignment")]
        public VerticalAlignment VerticalAlignment { get; set; }

        [XmlAttribute("Source")]
        public string Source
        {
            get
            {
                return this.Texture.ToString();
            }

            set
            {
                this.Texture = Managers.ContentManager.GetMenuTexture2D(value);
            }
        }

        [XmlAttribute("HorizontalAlignment")]
        public HorizontalAlignment HorizontalAlignment { get; set; }

        protected Texture2D Texture { get; private set; }

        internal override MenuComponentBase GetComponent(MenuComponentBase parent)
        {
            var comp = new Texture(this.Id, base.GetComponent(parent), this.Texture);
            comp.HorizontalAlignment = this.HorizontalAlignment;
            comp.VerticalAlignment = this.VerticalAlignment;
            comp.Dimension = new Dimension(0, 0, this.Width, this.Height);

            comp.Settle();

            return comp;
        }
    }
}